< previous page page_113 next page >

Page 113
but in reality these object creatures you create consume resources that need to be accounted for while you're constructing the system.
Note
In most cases, memory issues are not your concern when performing analytic studies of a problem being solved. Only during design and construction of the solution are you concerned with performance-related resource issues.

The best way to manage your runtime object creatures is to implement tactics to reduce the amount of memory space your application needs. Do not neglect to declare the return type of a Function method, that is, if you have a method of the following form:
Public Function createAccount()
as opposed to the following form:
Public Function createAccount() As SomeBankProductType
then the Function method implicitly defaults to
Public Function createAccount() As Variant
Variants require more memory than other types because of the underlying mapping to specific types. Further, remember to reclaim any memory allocated to a particular object variable. For instance, say you have a class named WireTransfer. You then instantiate an object of this type as follows:
Set theWireTransfer = New WireTransfer
or as follows:
Dim theWireTransfer As New WireTransfer
To reclaim memory occupied by theWireTransferand as good programming practiceyou should also include the following line of code when you're finished with this object:
Set theWireTransfer = Nothing
It's not easy to remember this important practice, and it takes time to form this habit.
Runtime constraints on object behavior also necessitate the practice of tracking and eliminating unused methods and attributes. If your Visual Basic class is becoming large with numerous methods, try restructuring your class by dividing it into other helper classes. This separation of concerns within large classes provides better memory efficiency because a smaller set of methods is housed in separate class modules. Visual Basic loads

 
< previous page page_113 next page >

If you like this book, buy it!